import { TypeOf } from '@blog/core';

export const TOKEN = 'token';
export const USER_INFO = 'userInfo';

export const getStorage = key => {
  const params = uni.getStorageSync(key);
  return params ? JSON.parse(params).data : false;
};

export const setStorage = (key, data) => {
  const params = {
    key: key,
    data: data
  };
  return uni.setStorageSync(key, JSON.stringify(params));
};

export const delStorage = keys => {
  if (TypeOf(keys) === 'string') {
    uni.removeStorageSync(keys);
  } else if (TypeOf(keys) === 'array') {
    keys.forEach(item => {
      uni.removeStorageSync(item);
    });
  }
};
